package com.demo.yang.enums;

import java.util.Map;

/**
 * 返回状态码
 * @author yinbenyang
 * @date 2017年11月3日下午5:51:38
 */
public enum StatusCode implements IndexedEnum {
	
	/**
	 * 公用提示语
	 */
	SUCCESS(ValidStatus.VALID.getIndex(), "成功"),
	FAILED(ValidStatus.INVALID.getIndex(), "失败"),
	ERROR(3, "系统繁忙，请稍后重试"),
	ILLEGAL_OPERATION(4, "非法操作"),
	NOPERMISSION(5, "权限不足"),
	SERVICE_UNAVAILABLE(6, "服务不可调用"),
	MISSING_PARAM(7, "参数缺失"),
	INVALID_PARAM(8, "参数非法"),
	//9-99预留
	
	/*
	 * 业务提示语
	 */
	ACCOUNT_NOT_EXIST(100,"账号不存在"),
	ACCOUNT_OR_PWD_ERROR(101,"账号或密码错误"),
	ACCOUNT_OR_PWD_NULL(102,"账号或密码为空"),
	;
	
	
	private int index;
	private String message;
	private static final Map<Integer, StatusCode> enumMap = IndexedEnumUtil.toIndexMap(StatusCode.values());
	StatusCode(int index, String message) {
		this.index = index;
		this.message = message;
	}

	@Override
    public int getIndex() {
	    return index;
    }

	@Override
    public String getMessage() {
	    return message;
    }

	/**
	 * 根据指定的索引获取枚举的定义
	 *
	 * @param index
	 * @return
	 */
	public static StatusCode valueOf(final int index) {
		return enumMap.get(index);
	}

}
